<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<div class="left-panel-search">
					<el-input class="input" v-model.trim="reqParams.sn" clearable placeholder="输入 SN 查询" />
					<el-button icon="el-icon-search" type="primary" @click="search" />
				</div>
			</div>
			<div class="right-panel">
				<div class="right-panel-search"></div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="tableRef"
				:api-obj="this.$API.reworkdoc.page"
				:params="reqParams"
				:column="column"
				row-key="id"
				stripe
				hideDo
				hideContextMenu>
				<el-table-column label="#" type="index" width="40" />
				<el-table-column align="center" fixed="right" label="操作" width="140">
					<template #default="scope">
						<el-button
							text
							type="primary"
							size="small"
							:disabled="scope.row.status !== 40"
							@click="open_detail(scope.row)"
							>详细</el-button
						>
						<el-divider direction="vertical" />
						<el-button
							text
							type="primary"
							size="small"
							:disabled="scope.row.status !== 10"
							@click="open_dialog(scope.row)">
							编辑</el-button
						>
					</template>
				</el-table-column>

				<template #reworkType="{ data }">
					<el-tag type="warning" v-if="data.reworkType === 1">{{ data.reworkTypeDesc }}</el-tag>
					<el-tag type="success" v-else-if="data.reworkType === 2">{{ data.reworkTypeDesc }}</el-tag>
					<el-tag type="info" v-else>{{ data.reworkTypeDesc }}</el-tag>
				</template>
				<template #needRelaunch="{ data }">
					<el-tag :type="data.needRelaunch ? '' : 'warning'">{{ data.needRelaunch ? '是' : '否' }}</el-tag>
				</template>
				<template #status="{ data }">
					<el-tag :type="tagType_status(data.status)">{{ data.statusDesc }}</el-tag>
				</template>
			</scTable>
		</el-main>

		<modify ref="modify" @complete="complete" />
		<detail ref="detail" />
	</el-container>
</template>

<script>
import modify from "./modify";
import detail from "./detail";


export default {
    components: {
        modify,
		detail,
    },
    data() {
        return {
            reqParams: {
                sn: '',
            },
            column: [
                { prop: "id", label: "id", width: 100, hide: true },
                { prop: 'doc', label: '返工单据', width: 130 },
                { prop: 'sn', label: 'SN', width: 160 },
                { prop: 'ngLineCode', label: '产线', width: 80 },
                { prop: 'ngOpCode', label: 'NG 工位', width: 80 },
                { prop: 'ngProcCode', label: 'NG 工序', width: 80 },
                { prop: 'reworkType', label: '返工类型', width: 100 },
                { prop: 'needRelaunch', label: '需重上线', width: 80 },
                { prop: 'relaunchProcCode', label: '重上线工序', width: 100 },
                { prop: 'status', label: '状态', width: 80 },
                { prop: 'operator', label: '返工人员', width: 100 },
                { prop: 'completedTime', label: '返工时间', width: 140 },
                { prop: 'createUser', label: '创建人', width: 100 },
                { prop: 'createTime', label: '创建时间', width: 140 },
            ],
        };
    },
    methods: {
        complete() {
            this.$refs.tableRef.refresh();
        },
        search() {
            this.$refs.tableRef.refresh();
        },
        open_dialog(row) {
            this.$refs.modify.open(row);
        },
		async open_detail(row) {
			await this.$refs.detail.open(row);
		},
        tagType_status(status) {
            switch (status) {
                case 10: return 'success';
                case 20: return 'warning';
                case 30: return 'danger';
                case 40: return '';
                default: return 'info';
            }
        },
    },
};
</script>
